package com.andova;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewParent;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.andova.empty.api.IEmptyActivityOption;
import com.andova.manager.AndovaModuleManager;
import com.andova.sample.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class EmptyStateActivity extends AppCompatActivity {
    private TextView mTextMessage;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    mTextMessage.setText(R.string.title_home);
                    return true;
                case R.id.navigation_dashboard:
                    mTextMessage.setText(R.string.title_dashboard);
                    return true;
                case R.id.navigation_notifications:
                    mTextMessage.setText(R.string.title_notifications);
                    return true;
            }
            return false;
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndovaModuleManager.obj().empty()
                .activityOption(this, layoutOption())
                .validIdList(this, validIdList())
                .emptyView(this, R.layout.ac_empty_state);

        mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }

    public void skip(View view) {
        startActivity(new Intent(this, SearchViewActivity.class));
        finish();
    }

    public IEmptyActivityOption layoutOption() {
        return new IEmptyActivityOption() {
            @Override
            public int emptyStateLayout() {
                return R.layout.page_empty_ac;
            }

            @Override
            public int errorStateLayout() {
                return 0;
            }

            @Override
            public int loadingStateLayout() {
                return 0;
            }

            @Override
            public void emptyStatePage(@Nullable View view, final ViewParent parent) {
            }

            @Override
            public void errorStatePage(@Nullable View view, ViewParent parent) {
            }

            @Override
            public void loadingStatePage(@Nullable View view, ViewParent parent) {
            }

            @Override
            public List<String> filterViewClassName() {
                List<String> list = new ArrayList<>(2);
                list.add(Toolbar.class.getSimpleName());
                list.add(BottomNavigationView.class.getName());
                return list;
            }

            @Override
            public List<Integer> filterViewId() {
                List<Integer> list = new ArrayList<>(1);
                list.add(R.id.message);
                return list;
            }
        };
    }

    public List<Integer> validIdList() {
        List<Integer> list = new ArrayList<>(2);
        list.add(R.id.ll_temp1);
        list.add(R.id.ll_temp2);
        return list;
    }
}
